package com.taoyibao.hongcanting.ui.mine.delegate;

import android.net.Uri;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.cache.SpUtils;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.constant.NetCode;
import com.taoyibao.hongcanting.model.CompanyBaseModel;
import com.taoyibao.hongcanting.model.UserInfoModel;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;
import com.taoyibao.hongcanting.utils.ToastUtils;

import java.util.List;


/**
 * @author TangAnna
 * @description:
 * @date :${DATA} 11:41
 */
public class UserInfoDelegate extends BackToolbarDelegate {
    public ImageView mIvHead;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_user_info;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("个人信息");
        mIvHead = get(R.id.iv_userInfo_head);
    }

    /**
     * 设置数据
     *
     * @param uiData
     */
    public void setUIData(CompanyBaseModel<List<UserInfoModel>> uiData) {
        //手机号
        ((TextView) get(R.id.tv_userInfo_phone)).setText(CodeUtils.formatHintPhone(SpUtils.getUserPhone()));

        if (uiData.code == NetCode.HTTP_200 && uiData.data != null && uiData.data.size() > 0) {
            UserInfoModel userInfoModel = uiData.data.get(0);
            //昵称
            if (!TextUtils.isEmpty(userInfoModel.nickname)) {
                ((TextView) get(R.id.tv_userInfo_nickname)).setText(userInfoModel.nickname);
            }
            //实名认证状态
            if (userInfoModel.user_verify != null) {
                if (userInfoModel.user_verify.status == CodeConstant.VERIFY_PARSS) {//已完成
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setTextColor(CodeUtils.getIdColor(R.color.color999));
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setText(CodeUtils.getIdString(R.string.string_wanCheng));
                } else if (userInfoModel.user_verify.status == CodeConstant.VERIFY_WAIT) {//审核中
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setTextColor(CodeUtils.getIdColor(R.color.color5ec));
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setText(CodeUtils.getIdString(R.string.string_shenHeZhong));
                } else if (userInfoModel.user_verify.status == CodeConstant.VERIFY_FAIL) {//失败
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setTextColor(CodeUtils.getIdColor(R.color.colorf84));
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setText(CodeUtils.getIdString(R.string.string_fail));
                } else {
                    ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setText(CodeUtils.getIdString(R.string.string_weiWanCheng));
                }
            } else {//没有进行实名认证
                ((TextView) get(R.id.tv_userInfo_verifiedStatus)).setText(CodeUtils.getIdString(R.string.string_weiWanCheng));
            }
            //头像
            if (!TextUtils.isEmpty(userInfoModel.avatar_url)) {
                GlideUtil.getInstance().loadDefaultCircleHead(getActivity(), userInfoModel.avatar_url, mIvHead);
            } else {
                mIvHead.setImageResource(R.drawable.default_touixiang);
            }
            //性别
            if (userInfoModel.gender == CodeConstant.MALE) {
                ((TextView) get(R.id.tv_userInfo_gender)).setText("男");
            } else if (userInfoModel.gender == CodeConstant.FEMALE) {
                ((TextView) get(R.id.tv_userInfo_gender)).setText("女");
            } else {
                ((TextView) get(R.id.tv_userInfo_gender)).setText("未设置");
            }
            //生日
            if (!TextUtils.isEmpty(userInfoModel.birth_date)) {
                ((TextView) get(R.id.tv_userInfo_birthday)).setText(userInfoModel.birth_date);
            } else {
                ((TextView) get(R.id.tv_userInfo_birthday)).setText("未设置");
            }
        }
    }

    /**
     * 设置昵称
     *
     * @param nickname
     */
    public void setNickname(String nickname) {
        if (!TextUtils.isEmpty(nickname)) {
            ((TextView) get(R.id.tv_userInfo_nickname)).setText(nickname);
        }
    }

    /**
     * 设置头像
     *
     * @param uri
     */
    public void setHead(Uri uri) {
        GlideUtil.getInstance().loadDefaultCircleHead(getActivity(), uri.toString(), mIvHead);
    }

    /**
     * 获取性别
     *
     * @return
     */
    public String getGrnder() {
        String grnder = ((TextView) get(R.id.tv_userInfo_gender)).getText().toString().trim();
        if (TextUtils.equals(grnder, "男")) {
            return CodeConstant.MALE + "";
        } else if (TextUtils.equals(grnder, "女")) {
            return CodeConstant.FEMALE + "";
        }
        ToastUtils.showToast(CodeUtils.getIdString(R.string.verified_hintGender));
        return "";
    }

    /**
     * 设置性别
     *
     * @param gender
     */
    public void setGender(String gender) {
        ((TextView) get(R.id.tv_userInfo_gender)).setText(gender);
    }

    /**
     * 设置生日
     *
     * @param birthday
     */
    public void setBirthday(String birthday) {
        ((TextView) get(R.id.tv_userInfo_birthday)).setText(birthday);
    }

    /**
     * 获取生日
     *
     * @return
     */
    public String getBirthday() {
        return ((TextView) get(R.id.tv_userInfo_birthday)).getText().toString().trim();
    }
}
